package com.csun.dsms.task;

import com.csun.dsms.mapper.JyDataMapper;
import com.csun.dsms.model.education.JyProblemManagement;
import com.csun.dsms.model.huang.HgReminderData;
import com.csun.dsms.service.HgReminderDataService;
import com.csun.dsms.utils.pt.HuangGangUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Slf4j
@Component
@EnableScheduling
public class JtReminderTask {

    @Resource
    private JyDataMapper jyDataMapper;

    @Resource
    private HgReminderDataService hgReminderDataService;


    // 每天凌晨 2 点执行一次
    @Scheduled(cron = "0 0 2 * * ?")
    public void addReminder(){
        List<JyProblemManagement> jyProblemManagements = jyDataMapper.queryListByTimeout();
        System.out.println(jyProblemManagements);
        for (JyProblemManagement jyProblemManagement : jyProblemManagements) {
            HgReminderData hgReminderDataNew = new HgReminderData();
            Date date = new Date();
            hgReminderDataNew.setReminderPerson(jyProblemManagement.getReportUser());
            hgReminderDataNew.setCreatedTime(date);
            hgReminderDataNew.setReminderDepart(jyProblemManagement.getDepartment());
            hgReminderDataNew.setReminderPhoneNumber(jyProblemManagement.getReportUserPhone());
            hgReminderDataNew.setReminderTime(date);
            hgReminderDataNew.setReminderType(2);
            hgReminderDataNew.setReminderContent(jyProblemManagement.getReportUser()+ "有办件超期了，请注意！");
            hgReminderDataNew.setReminderTitle(jyProblemManagement.getReportUser()+ "有办件超期了，请注意！");
            hgReminderDataService.save(hgReminderDataNew);
//            HuangGangUtil.sendMsg(hgReminderDataNew);
        }
    }
}
